From: Petr Viktorin Date: Tue, 16 Dec 2025 12:20:48 +0000 (+0100) Subject: gh-142754: Ensure that Element & Attr instances have the ownerDocument attribute... X-Git-Tag: archive/raspbian/3.9.2-1+rpi1+deb11u6^2~7 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/%22mailto:ematirov%40gmail.com//%22mailto:i18n-csb%40linuxcsb.org/%22/%22http:/www.example.com/%22mailto:ematirov%40gmail.com/%22mailto:i18n-csb%40linuxcsb.org/%22?a=commitdiff_plain;h=f525b54411c1bfbf0f5a2df21c3585a3149263ec;p=python3.9.git gh-142754: Ensure that Element & Attr instances have the ownerDocument attribute (#142794) Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Origin: backport, https://github.com/python/cpython/commit/1cc7551b3f9f71efbc88d96dce90f82de98b2454 Debian-Bug: https://bugs.debian.org/1122875 Gbp-Pq: Name CVE-2025-12084-2.patch --- diff --git a/Lib/test/test_minidom.py b/Lib/test/test_minidom.py index 840a3f5..0868ff4 100644 --- a/Lib/test/test_minidom.py +++ b/Lib/test/test_minidom.py @@ -10,7 +10,7 @@ import unittest import pyexpat import xml.dom.minidom -from xml.dom.minidom import parse, Node, Document, parseString +from xml.dom.minidom import parse, Attr, Node, Document, Element, parseString from xml.dom.minidom import getDOMImplementation from xml.parsers.expat import ExpatError @@ -181,6 +181,14 @@ class MinidomTest(unittest.TestCase): # This example used to take at least 30 seconds. self.assertLess(end - start, 10) + def testSetAttributeNodeWithoutOwnerDocument(self): + # regression test for gh-142754 + elem = Element("test") + attr = Attr("id") + attr.value = "test-id" + elem.setAttributeNode(attr) + self.assertEqual(elem.getAttribute("id"), "test-id") + def testAppendChildFragment(self): dom, orig, c1, c2, c3, frag = self._create_fragment_test_nodes() dom.documentElement.appendChild(frag) diff --git a/Lib/xml/dom/minidom.py b/Lib/xml/dom/minidom.py index 3a91295..e4e8b42 100644 --- a/Lib/xml/dom/minidom.py +++ b/Lib/xml/dom/minidom.py @@ -348,6 +348,7 @@ class Attr(Node): def __init__(self, qName, namespaceURI=EMPTY_NAMESPACE, localName=None, prefix=None): self.ownerElement = None + self.ownerDocument = None self._name = qName self.namespaceURI = namespaceURI self._prefix = prefix @@ -671,6 +672,7 @@ class Element(Node): def __init__(self, tagName, namespaceURI=EMPTY_NAMESPACE, prefix=None, localName=None): + self.ownerDocument = None self.parentNode = None self.tagName = self.nodeName = tagName self.prefix = prefix diff --git a/Misc/NEWS.d/next/Library/2025-12-16-11-55-55.gh-issue-142754.xuCrt3.rst b/Misc/NEWS.d/next/Library/2025-12-16-11-55-55.gh-issue-142754.xuCrt3.rst new file mode 100644 index 0000000..d4e158c --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-12-16-11-55-55.gh-issue-142754.xuCrt3.rst @@ -0,0 +1,4 @@ +Add the *ownerDocument* attribute to :mod:`xml.dom.minidom` elements and attributes +created by directly instantiating the ``Element`` or ``Attr`` class. Note that +this way of creating nodes is not supported; creator functions like +:py:meth:`xml.dom.Document.documentElement` should be used instead.